import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
import { OrderType } from 'src/app/constants/order-type';

@Component({
    selector: 'app-order-create-dialog',
    templateUrl: './order-create-dialog.component.html',
    styleUrls: ['./order-create-dialog.component.sass'],
})
export class OrderCreateDialogComponent implements OnInit {
    orderCreateForm = new FormGroup({
        type: new FormControl(OrderType.Xiaomian),
        count: new FormControl(1, [Validators.required, Validators.min(1)]),
    });

    constructor(private dialogRef: MatDialogRef<OrderCreateDialogComponent>) {}

    ngOnInit(): void {}

    cancel() {
        this.dialogRef.close();
    }

    submit() {
        this.dialogRef.close({
            type: this.orderCreateForm.get('type')?.value,
            count: this.orderCreateForm.get('count')?.value,
        });
    }
}
